package cn.marinda.listener;

import cn.marinda.util.ServerUtils;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 插件列表中选择事件
 *
 * @author admin
 * @date 2022/07/16
 */
public class PluginListSelectionEvent implements ListSelectionListener {

    public JList<String> pluginList;
    /**
     * 插件列表中选择事件
     *
     * @param pluginList 插件列表
     */
    public PluginListSelectionEvent(JList pluginList){
        this.pluginList = pluginList;

    }

    @Override
    public void valueChanged(ListSelectionEvent e) {
        Set<String> list = new HashSet<>();
//        松下鼠标
        if(!e.getValueIsAdjusting()){
            int [] selectNumber = pluginList.getSelectedIndices();
            ListModel model = pluginList.getModel();
            for(int i : selectNumber){
                String obj = model.getElementAt(i).toString();
                list.add(obj);
            }
        }
        ServerUtils.serverPluginSet = list;

    }
}
